<?php
/**
 * Created by PhpStorm.
 * User: xuzhong
 * Date: 2025/4/2
 * Time: 13:55
 */

namespace app\admin\model;
use think\Model;

class  MinerPool extends BaseModel
{
    // 定义数据表名
    protected $name = 'miner_pool';

    // 定义主键
    protected $primaryKey = 'id';

    // 定义创建时间字段名
    protected $createTime = 'create_time';

    // 定义更新时间字段名
    protected $updateTime = 'update_time';
    // 定义自动时间戳
    protected $autoWriteTimestamp = true;

    // 设置字段信息
    protected $schema = [
        'id'          => 'int',
        'name'       => 'string',
        'image'       => 'string',
        'link'      => 'string',
        'create_time' => 'datetime',
        'update_time' => 'datetime',
        'creator'     => 'int',
        'updater'     => 'int',
        'is_del'      => 'int',

    ];
    protected $attributes = [

    ];

    public function getAttr($name)
    {
        // 检查是否是要处理的特殊属性
        if (strpos($name, '_value') !== false) {
            $originalField = str_replace('_value', '', $name);
            if (isset($this->attributes[$originalField])) {
                $value = $this->getData($originalField);
                return $this->attributes[$originalField][$value] ?? '未知';
            }
        }

        // 如果不是特殊属性，调用父类的方法
        return parent::getAttr($name);
    }

    /**
     * @describe
     * @author: Bobo
     * @date: 2025-02-11 17:05:24
     * @param [type] @required
     * @return Renderable
     */
    public function getFieldEnum($field = 'all')
    {
        return $this->getEnum(strtoupper($field), [], 'label');
    }

}